﻿using System;
using System.Drawing;
using System.Reflection;

namespace HYCodeBase.WinForm.WinFormRemindSuit
{
	internal class GeneralAttributeFactory : IAttributerGSFactory
	{
		public IAttributeGeter GetUseGeter(ControlPacker inputControl, string inputAttributeName)
		{
			if (inputAttributeName == this.m_strNameItems || inputAttributeName == this.m_strNameNodes)
			{
				return SpecialControlAttributeGeter.GetSpecialControlPropertyGeter();
			}
			if (inputControl.UseCustomFormatter != null && !inputAttributeName.Equals("Name"))
			{
				return new CustomAttributeGetterSetter(inputControl);
			}
			return BaseReflectPropertyGeter.GetBaseReflectPropertyGeter();
		}

		public IAttributeSeter GetUseSeter(ControlPacker inputControl, string inputAttributeName)
		{
			if (inputControl.UseCustomFormatter != null)
			{
				return new CustomAttributeGetterSetter(inputControl);
			}
			IAttributeSeter result;
			try
			{
				if (inputAttributeName == this.m_strNameNodes || inputAttributeName == this.m_strNameItems)
				{
					result = SpecialControlAttributeSeter.GetSpecialControlPropertySeter();
				}
				else
				{
					PropertyInfo property = inputControl.UseControl.GetType().GetProperty(inputAttributeName);
					if (null == property)
					{
						result = null;
					}
					else
					{
						Type propertyType = property.PropertyType;
						if (propertyType == typeof(bool))
						{
							result = BoolReflectPropertySeter.GetBoolReflectPropertySeter();
						}
						else if (propertyType == typeof(string))
						{
							result = StringReflectPropertySeter.GetStringReflectPropertySeter();
						}
						else if (propertyType == typeof(int))
						{
							result = IntReflectPropertySeter.GetIntReflectPropertySeter();
						}
						else if (propertyType == typeof(System.Drawing.Point))
						{
							result = PointReflectPropertySeter.GetPointReflectPropertySeter();
						}
						else
						{
							result = StringReflectPropertySeter.GetStringReflectPropertySeter();
						}
					}
				}
			}
			catch (Exception)
			{
				result = null;
			}
			return result;
		}

		private string m_strNameItems = "Items";

		private string m_strNameNodes = "Nodes";
	}
}
